package com.geek.javase.ch12.work;

import java.io.*;

/*
 *@author wangpeng
 *2025/10/23 18:29
 *@description TODO
 */

//文件拷贝
//1.选择使用哪一个流对象  ---->FileInputStream,选择字节流

public class Demo3 {
    public static void main(String[] args) {
        String srcFile = "copyFile1.txt"; // 源文件路径
        String destFile = "copyFile2.txt"; // 目标文件路径

        try (InputStream fis = new FileInputStream(srcFile);
             OutputStream fos = new FileOutputStream(destFile)) {

            byte[] buffer = new byte[1024]; // 按桶取
            int bytesRead;

            while ((bytesRead = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, bytesRead);
            }
            System.out.println("文件拷贝完成！");

        } catch (FileNotFoundException e) {
            System.err.println("文件未找到: " + e.getMessage());
        } catch (IOException e) {
            System.err.println("IO异常: " + e.getMessage());
        }
    }
}







